package com.duoec.magichour.core.utils;

import com.duoec.magichour.core.CommonConst;
import com.google.common.io.Files;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

/**
 * 文件系统操作
 * Created by ycoe on 17/7/5.
 */
public class FileUtils {
    private static final Logger logger = LoggerFactory.getLogger(FileUtils.class);

    private FileUtils() {
    }

    public static void writeStringToFile(File file, String content) throws IOException {
        File dir = file.getParentFile();
        if (!dir.exists()) {
            boolean success = dir.mkdirs();
            if (!success) {
                //创建目录失败，忽略...
                logger.error("创建目录失败：{}", dir.getAbsolutePath());
            }
        }
        Files.write(content, file, Charset.forName(CommonConst.ENCODE));
    }
}
